package com.acce.core.pushlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import nl.justobjects.pushlet.core.Dispatcher;
import nl.justobjects.pushlet.core.Event;

public class PublisherServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -9151773182575447180L;

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		multicast();
		//broadcast();
		//request.getRequestDispatcher("chat.jsp").forward(request, response);
	}

	private void unicast() {
		Event event = Event.createDataEvent("/order/buyerlist");
		event.setField("hw", "Unicast msg");
		Dispatcher.getInstance().unicast(event, "piero"); // 向ID为piero的用户推送
	}

	private void multicast() {
		Event event = Event.createDataEvent("/order/buyerlist");
		event.setField("hw", "Multicast msg");
		Dispatcher.getInstance().multicast(event); // 向所有和myevent1名称匹配的事件推送
	}

	private void broadcast() {
		Event event = Event.createDataEvent("/order/buyerlist"); // 向所有的事件推送，不要求和这儿的myevent1名称匹配
		event.setField("hw", "Broadcast msg");
		Dispatcher.getInstance().broadcast(event);
	}

}
